<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>贪夜蛾自动检测云系统</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" th:src="@{/static/easyui/jquery.min.js}"></script>
<link th:href="@{/static/login/css/style.css}" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
	<!-- main -->
	<div class="agileits-main"> 
	<div class="w3top-nav">
				<div class="w3top-nav-left">	
					<h1><a href="login.html">贪夜蛾自动检测云系统</a></h1>
				</div>
				<div class="clear"></div>
			</div>	
		<div class="header-main">
		<h2>Login Now</h2>
			<div class="header-bottom">
				<div class="header-right w3agile">
					<div class="header-left-bottom agileinfo">
                        <form id="fm">
						<div class="icon1">
							<input type="email" placeholder="Username" id='username' name="username" required=""/>
						</div>
						<div class="icon1">
							<input type="password" placeholder="Password" id="password" name="password" required=""/>
						</div>
                        </form>
						<div class="bottom">
							<input type="submit" onclick="Login()" value="登录" />
						</div>
<!--						<div class="bottom">-->
<!--							<input type="submit" onclick="Resign()" value="Resign" />-->
<!--						</div>-->
<!--						<p><a href="#">Forgot Password?</a></p>-->

					</div>
				</div>
			</div>

	</div>

	</div>


</body>
<script type="text/javascript">
	function Login() {
		var username = $("#username").val()
		var password = $('#password').val();

		var datas = {"username":  username ,"password":password };
		//将实体类转换为json
		//var datas = JSON.stringify(data);
		//alert(data);
		if (username == "") {
			alert("用户名不能为空");
			return;
		}
		if (password == "") {
			alert("密码不能为空");
			return;
		}
		$.ajax({
			url: "user/login",
			data: $("#fm").serialize(),
            dataType:'json',
			type: "post",
			success: function (data) {
				if (data.msg == 1) {
					if(data.role == '普通用户'){
						window.self.location = "/customer";
					}else {
						window.self.location = "/admin";
					}
				} else {
					alert("用户名或密码错误！");
					//window.location.href = "login.html";
				}
			}
		});
	}
</script>
</html>